<template>
  <div class="add-form f-c">
    <div class="header">
      <div class="title">
        评审申报信息填写（项目单位申请）
      </div>
    </div>
    <div class="add-form-content f-g">
      <SubmitForm
        :rule-form="ruleForm"
        :rules="rules"
        :form-list="formList"
        @save="onSave"
      />
    </div>
  </div>
</template>

<script>
import { http } from '@/api'
import { MeetingType, PaperType } from '@/dict'
export default {
  name: 'FormAdd',
  data() {
    return {
      dialogValue: false,
      ruleForm: {
      },
      rules: {
        projectName: [{ required: true, message: '不能为空' }]
      },
      formList: [
        {
          key: 'projectName',
          name: 'input',
          label: '项目名称',
          colSpan: 12
        },
        {
          key: 'meetingType',
          name: 'select',
          label: '会议类别',
          options: MeetingType,
          colSpan: 12
        },
        {
          key: 'pocket',
          name: 'input',
          type: 'number',
          label: '资金（万元）',
          colSpan: 12
        },
        {
          key: 'capital',
          name: 'input',
          label: '投资方',
          colSpan: 12
        },
        {
          key: 'contacts',
          name: 'input',
          label: '联系人',
          colSpan: 12
        },
        {
          key: 'phone',
          name: 'input',
          label: '联系电话',
          colSpan: 12
        },
        {
          key: 'address',
          name: 'input',
          label: '建设地址',
          colSpan: 24
        },
        {
          key: 'projectContent',
          name: 'input',
          type: 'textarea',
          label: '项目内容',
          colSpan: 24
        },
        {
          name: 'title',
          label: '附件资料',
          colSpan: 24
        },
        {
          key: 'paper',
          name: 'select',
          label: '纸张',
          options: PaperType,
          colSpan: 12
        },
        {
          key: 'pages',
          name: 'input',
          type: 'number',
          label: '页数',
          colSpan: 12
        },
        {
          key: 'savingCapital',
          name: 'input',
          type: 'number',
          label: '节约资金（元）',
          colSpan: 12
        },
        {
          key: 'files',
          name: 'files',
          multiple: true,
          defaultValue: [],
          label: '',
          description: '备注：需要上传ppt、环评报告'
        }
      ]
    }
  },
  created() {

  },
  methods: {
    getForm() {
      const form = {
        id: undefined,
        category: 1,
        files: []
      }
      this.formList.forEach(el => {
        if (el.key) {
          form[el.key] = el.defaultValue || ''
        }
      })
      return form
    },
    async open(item) {
      this.ruleForm = this.getForm()
      if (item) {
        for (const key in this.ruleForm) {
          this.ruleForm[key] = item[key] ? item[key] : this.ruleForm[key]
        }
      }
      this.dialogValue = true
    },
    onPageBack() {
      this.$emit('get-page')
      this.dialogValue = false
    },
    onSave() {
      http.project_center.create({ ...this.ruleForm }).then(res => {
        this.$message.success(res.msg)
        this.onPageBack()
      })
    }
  }
}
</script>

<style scoped lang="scss">
</style>
